<!--
打开
<el-button link type="primary" icon="Setting" @click="$refs['<%= fileName %>'].show(scope.row.deptId, scope.row)">配置管理</el-button>

引用
<<%= FileName %> ref="<%= fileName %>" />

引入
import <%= FileName %> from './<%= fileName %>.vue'
-->

<template>
    <!--  todo 对话框 -->
    <el-dialog title="todo" v-model="open" width="1200px" append-to-body>
        <el-form ref="formRef" :model="form" :rules="rules" label-width="130px">
            <el-row>
                <el-col :span="12">
                    <el-form-item label="是否默认配置" prop="isDefault">
                        <el-radio-group v-model="form.isDefault">
                            <el-radio :value="0">否</el-radio>
                            <el-radio :value="1">是</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="单位代码" prop="orgCode">
                        <el-input v-model="form.orgCode" placeholder="请输入单位代码" clearable />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="系统介绍" prop="systemInfo">
                        <el-input v-model="form.systemInfo" type="textarea" placeholder="请输入系统介绍" clearable />
                    </el-form-item>
                </el-col>
                <!-- 图片上传 -->
                <!-- <el-col :span="6">
                    <el-form-item label="组织logo（png）" prop="siderLogo">
                        <ImageUpload v-model="form.siderLogo" :limit="1" size="small" />
                    </el-form-item>
                </el-col> -->

                <!-- 数据字典 -->
                <!-- <el-form-item label="模型类型" prop="modelType">
                    <el-select v-model="form.modelType" placeholder="请选择模型类型">
                        <el-option v-for="dict in org_app_menu_expand_type" :key="dict.value" :label="dict.label"
                            :value="dict.value"></el-option>
                    </el-select>
                </el-form-item> -->
                <!-- <el-form-item label="配置状态">
                    <el-radio-group v-model="form.status">
                        <el-radio v-for="dict in sys_normal_disable" :key="dict.label" :value="dict.value">{{
                            dict.label}}</el-radio>
                    </el-radio-group>
                </el-form-item> -->
            </el-row>
        </el-form>
        <!-- 底部按钮 -->
        <template #footer>
            <div class="dialog-footer">
                <el-button type="primary" @click="submitForm" :disabled="loadingRef">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup name="<%= fileName %>">
import { ref, getCurrentInstance } from 'vue';
import { addDeptExpandInfo, editDeptExpandInfo } from "@/api/sys/deptExpandInfo";//todo api：新增、编辑
import { getDeptExpandInfoByDeptId } from "@/api/sys/org"; //todo api：详情
//import ImageUpload from "../deptExpandInfo/imageUpload.vue"; //todo 图片上传组件

//数据字典
// const { proxy } = getCurrentInstance();
// const { org_app_menu_expand_type,sys_normal_disable } = proxy.useDict('org_app_menu_expand_type','sys_normal_disable');


const form = ref({
    //todo 表单数据（复制自动生成）
    deptExpandInfoId: undefined,
    deptId: undefined,
    orgCode: undefined,
    version: undefined,
    faviconSvg: "",
    faviconIcon: "",
    siderLogo: "",
    userIcon: "",
    title: undefined,
    systemInfo: undefined,
    introduce: undefined,
    welcome: undefined,
    inputPlaceholder: undefined,
    underInputPlaceholder: undefined,
    sendIcon: "",
    noSendIcon: "",
    isDefault: 0,
    createBy: undefined,
    createTime: undefined,
    updateBy: undefined,
    updateTime: undefined,
});
const { proxy } = getCurrentInstance();

const formRef = ref();
const open = ref(false);
const loadingRef = ref(false)

// 表单校验
const rules = ref({
    orgCode: [
        { required: true, message: "单位代码不能为空", trigger: "blur" }
    ],
});


/**显示对话框 */
const idRef = ref()//页面id
function show(pageId, row) {
    reset();
    // console.log('参数', pageId, row)
    idRef.value = pageId;
    getData(row);
    open.value = true;
}
function reset() {
    form.value = {
        //todo 表单数据（复制自动生成）
        deptExpandInfoId: undefined,
        deptId: undefined,
        orgCode: undefined,
        version: undefined,
        faviconSvg: "",
        faviconIcon: "",
        siderLogo: "",
        userIcon: "",
        title: undefined,
        systemInfo: undefined,
        introduce: undefined,
        welcome: undefined,
        inputPlaceholder: undefined,
        underInputPlaceholder: undefined,
        sendIcon: "",
        noSendIcon: "",
        isDefault: 0,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined
    };
    proxy.resetForm(formRef);
}
/** 提交 */
async function submitForm() {
    const valid = await proxy.$refs["formRef"].validate().catch(e => e);
    if (valid === true) {
        try {
            let params = {
                ...form.value
            }
            if (params.deptExpandInfoId != null) {
                await editDeptExpandInfo(params);
                proxy.$modal.msgSuccess("保存成功");
            } else {
                await addDeptExpandInfo(params);
                proxy.$modal.msgSuccess("保存成功");
            }
            open.value = false;
            // getList();
        } catch (err) {
            console.log(err);
        }
    } else {
        ElMessage.warning(`请根据以上${Object.keys(valid)?.length}项提示修改内容`)
    }
}

/** 取消 */
function cancel() {
    open.value = false;
}


//获取数据
function getData(row) {
    loadingRef.value = true
    // const params = { deptAppMenuId: idRef.value }
    getDeptExpandInfoByDeptId(idRef.value).then(response => {
        if (response.data) {
            //修改
            response.data.isDefault = Number(response.data.isDefault);
            form.value = response.data
        }
        else {
            //新增
        }
        loadingRef.value = false
    });
}


defineExpose({ show });//父组件调用必须通过expose暴露出去
</script>